(function (vc, vm) {
    vc.extends({
        data: {
            editDistributionModeInfo: {
                modeId: '',
                modeName: '',
                fixedFee: '',
                startDeliveryIn: '',
                startDeliveryOut: '',
                maximumDistribution: '',
                shopId: '',
                isShow: '200'
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editDistributionMode', 'openEditDistributionModeModal', function (_params) {
                $that.refreshEditDistributionModeInfo();
                $('#editDistributionModeModel').modal('show');
                vc.copyObject(_params, $that.editDistributionModeInfo);
                if ($that.editDistributionModeInfo.fixedFee != '-1.00') {
                    $that.editDistributionModeInfo.isShow = '100';
                }
                $that.editDistributionModeInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editDistributionModeValidate: function () {
                return vc.validate.validate({
                    editDistributionModeInfo: $that.editDistributionModeInfo
                }, {
                    'editDistributionModeInfo.modeId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "派送方式ID不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "派送方式ID不能超过30"
                        },
                    ],
                    'editDistributionModeInfo.modeName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "方式名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "方式名称不能超过30"
                        },
                    ]
                });
            },
            editDistributionMode: function () {
                if (!$that.editDistributionModeValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    '/distributionMode/updateDistributionMode',
                    JSON.stringify($that.editDistributionModeInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editDistributionModeModel').modal('hide');
                            vc.emit('distributionModeManage', 'listDistributionMode', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditDistributionModeInfo: function () {
                $that.editDistributionModeInfo = {
                    modeId: '',
                    modeName: '',
                    fixedFee: '',
                    startDeliveryIn: '',
                    startDeliveryOut: '',
                    maximumDistribution: '',
                    shopId: '',
                    isShow: '200'
                }
            }
        }
    });
})(window.vc, window.$that);
